<?php
class registereduser extends head2d {
 function registereduser() {
  $this->table = "registereduser";
  $this->linetable = 'registereduserline' ;
  $this->lineatts = 3 ;
  $this->getmetadata();
  $this->maintainhist = true;
  $this->header[2] = "";
  $_SESSION[$this->table] = $this;
 }
 function createblank() {
  parent::createblank();
  $this->header[6] = date("Y-m-d H:i:s");
  $this->header[7] = '';
  $this->header[8] = 'Y';
 } 

 function showform() { 
  $t = micro_time();     
  echo '<head>';
  ECHO SCRIPTS ;
  echo '</head>';
  echo "<body onload='document.form.f0.focus()'>";
  echo "<h1>Registered User Setup</h1>"; 
  echo "<form name='form' method=POST>";
  echo "<input type=hidden name=res value=''>";
  echo "<table>";
  if ($this->header[2] == '0') {
   echo $this->htmlrow('0','User Name');
  } else {
   echo $this->htmlrow('0','User Name ','disabled');
  }
  echo $this->htmlrow('1','Name');
  echo $this->htmlrow('5');
  echo "</table>";  
  echo "<input type=hidden name=t value=".micro_time().">";
  echo '<input class=bt accesskey=A type=submit name=sub value=Apply>';
  if ($this->header[2] != '0') {
   echo '<input class=bt accesskey=D type=submit name=sub value=Delete>';
  }
  echo '<input class=bt accesskey=S type=submit name=sub value=Save>';
  echo '<button type=button class=bt onclick=rest()><span>Restart</span></button>'; 
  echo "</form>"; 
 } 

 function applyfromrequest() {
  $this->valid = true;
  // Goes through request. Applies if legal, otherwise error.
    $this->valids = array_fill(0,$this->atts,'');

  if (isset($_REQUEST["f0"])) {
   $f = $_REQUEST["f0"];
   $exists = freaditem("registereduser",$f) ;
   if(preg_match('/^[0-9a-zA-Z@\'\.-]{2,45}$/',$f)) {
    if ($exists != "") {
	 $this->valids[0] = "That user already exists";
    } else {
     $this->header[0] = $f;
     $this->lines[0][0] = $f;	
     $this->lines[0][1] = '0';	
     $this->lines[0][2] = "invited";
	}
   } else {
    $this->valids[0] = "Please enter a valid name letters and numbers only";
   }
 }

  if (isset($_REQUEST["f1"])) {
   // name. Allowable characters A-Za-z-space apostrophe
   $f = $_REQUEST["f1"];
   if(preg_match('/^[0-9a-z A-Z\'\.-]{2,45}$/',$f)) {
    $this->header[1] = $f; 
   } else {
    $this->valids[1] = "Please enter a valid name letters and numbers only";
   }
  }  

  if (isset($_REQUEST["f5"])) {
   //Password
   $f = $_REQUEST["f5"];
   if(preg_match('/^[0-9a-z A-Z\'\.-]{2,45}$/',$f)) {
    $this->header[5] = $f; 
   } else {
    $this->valids[5] = "Please enter a password letters and number sonly";
   }
  }  
 
  $this->valid = every($this->valids,"");
  if ($this->valid) {
   if ($this->header[0] == "") $this->valids[0] = "Incomplete";
   if ($this->header[1] == "") $this->valids[1] = "Incomplete";
   $this->valid = every($this->valids,"");   
  }
   
 }
}
?>